package com.easylinkin.linkappapi.webcammanage.controller;

import com.easylinkin.linkappapi.webcammanage.entity.QueryHistogramBean;
import com.easylinkin.linkappapi.webcammanage.service.DataStatisticsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;
import site.morn.rest.RestBuilders;
import site.morn.rest.RestMessage;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 数据统计Controller
 */
@RestController
@RequestMapping("/dataStatistics")
@Slf4j
public class DataStatisticsController {

    @Autowired
    private DataStatisticsService dataStatisticsService;

    @GetMapping("momData")
    public RestMessage momData() {
        return RestBuilders.successBuilder().data(dataStatisticsService.momData()).build();
    }

    @PostMapping("histogram")
    public RestMessage histogram(@RequestBody QueryHistogramBean queryHistogramBean) {
        Assert.notNull(queryHistogramBean, "queryHistogramBean 不能为空");
        return RestBuilders.successBuilder().data(dataStatisticsService.histogram(queryHistogramBean)).build();
    }

    @PostMapping("exportHistogram")
    public void exportHistogram(@RequestBody QueryHistogramBean queryHistogramBean, HttpServletRequest request, HttpServletResponse response) {
        Assert.notNull(queryHistogramBean, "queryHistogramBean 不能为空");
        dataStatisticsService.exportHistogram(queryHistogramBean, request, response);
    }

}
